package com.tedu.api.io;

import java.io.File;
import java.io.FileFilter;
public class HomeWork2 {
    public static void main(String[] args) {

        String dirPath = "path/to/your/testDir";
        File dir = new File(dirPath);

        File[] txtFiles = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.isFile() && file.getName().endsWith(".txt");
            }
        });
        printFiles(txtFiles, ".txt files:");



        File[] javaFiles = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.isFile() && file.getName().endsWith(".java");
            }
        });
        printFiles(javaFiles, ".java files:");


        File[] hiddenFiles = dir.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.isHidden() || (file.isFile() && file.getName().startsWith("."));
            }
        });
        printFiles(hiddenFiles, "hidden files:");
    }

    private static void printFiles(File[] files, String label) {
        if (files != null) {
            System.out.println(label);
            for (File file : files) {
                System.out.println(file.getName());
            }
        } else {
            System.out.println(label + " (directory is not accessible or empty)");
        }
    }
}










